from lib.ZLoadJson import ZLoadJson
from lib.res.fun import _cutImg , _create_image_alpha , _change_size
from resource.script.Button.lib.ItemBtn import ItemBtn
from resource.script.Item.res.glo import _i_src


class Item ( object ) :
	def __init__ ( self , father , id ) :
		super ( Item , self ).__init__ ( )
		self.id = id
		if id != int ( 0 ) :
			self.data = ZLoadJson ( _i_src [ 'data' ] [ 'item' ] [ id ] )
			self.name = self.data.get ( ) [ 'name' ]
			self.type = self.data.get ( ) [ 'type' ]
			self.effect = self.data.get ( ) [ 'effect' ]
			images = _cutImg ( _create_image_alpha ( self.data.get ( ) [ 'icon-big' ] ) )
			self.image = ItemBtn ( father ,
			                       images [ self.data.get ( ) [ 'icon-small' ] ] ,
			                       images [ self.data.get ( ) [ 'icon-small' ] ] ,
			                       self )
			self.image._pos = 20 , 20
		else :
			self.data = ZLoadJson ( _i_src [ 'data' ] [ 'item' ] [ id ] )
			self.name = self.data.get ( ) [ 'name' ]
			self.type = self.data.get ( ) [ 'type' ]
			self.effect = self.data.get ( ) [ 'effect' ]
			image = _change_size ( _create_image_alpha ( self.data.get ( ) [ 'icon-big' ] ) , father._size )
			self.image = ItemBtn ( father ,
			                       image ,
			                       image ,
			                       self )
			self.image._pos = 0 , 0

	def draw ( self ) :
		self.image.draw ( )

	def update ( self , event , pos , key ) :
		self.image.update ( event , pos , key )
